<template>
  <div class="theDocumentary">
    <div>
      <div class="cgName"><b>应付账款（财务）</b> </div>
      <div style="margin-top: 15px">
        <el-radio-group v-model="queryParams.selectType" size="medium" @change="jihuaChange(queryParams.selectType)">
          <el-radio-button label="0">应付单列表</el-radio-button>
          <el-radio-button label="1">今日新增</el-radio-button>
          <el-radio-button label="2">本周新增</el-radio-button>
          <el-radio-button label="3">本月新增</el-radio-button>
        </el-radio-group>
        <el-button type="success" size="medium"  @click="newAdd" >新增</el-button>
        <div class="pageTop" style="margin-top: 15px">
          <el-form :model="queryParams" ref="queryParams" :inline="true" class="inputWidth"  style="padding: 0px 10px; padding-top: 20px;" >
            <el-form-item label="付款单号" >
              <el-input
                v-model="queryParams.accountsPayableCode"
                placeholder="请输入付款单号"
                clearable
                size="medium"
              />
            </el-form-item>
            <el-form-item label="供应商" >
              <el-select
                v-model="queryParams.supplierId"
                placeholder="请选择"
                clearable
                size="medium">
                <el-option
                  v-for=" item in gysList"
                  :key="item.supplierId"
                  :label="item.supplierName"
                  :value="item.supplierId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="状态" >
              <el-select
                v-model="queryParams.procurementStatus"
                placeholder="请选择"
                clearable
                size="medium">
                <el-option
                  v-for=" item in ztList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="单据日期">
              <el-date-picker
                v-model="djDateList"
                size="medium"
                @change="riqiChange(djDateList)"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="datetimerange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <!--            <el-form-item label="付款日期">-->
            <!--              <el-date-picker-->
            <!--                v-model="fkDateList"-->
            <!--                @change="fkriqichange(fkDateList)"-->
            <!--                size="medium"-->
            <!--                value-format="yyyy-MM-dd HH:mm:ss"-->
            <!--                type="datetimerange"-->
            <!--                range-separator="-"-->
            <!--                start-placeholder="开始日期"-->
            <!--                end-placeholder="结束日期"-->
            <!--              ></el-date-picker>-->
            <!--            </el-form-item>-->
            <el-form-item label="">
              <el-button type="primary" size="medium" @click="getList">搜索</el-button>
            </el-form-item>
          </el-form>

        </div>
        <el-table v-loading="loading" :data="dataList" stripe border style="margin-top: 20px" :header-cell-style="{background:'#eef1f6',color:'#606266'}">
          <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
          <el-table-column align="center" label="付款单号"   property="accountsPayableCode" width="200"   ></el-table-column>
          <el-table-column align="center" label="供货商"   property="supplierName"  ></el-table-column>
          <el-table-column align="center" label="付款总数"   property="totalPayment"  ></el-table-column>
          <el-table-column align="center" label="付款日期"   property="payTime"  width="180"></el-table-column>

          <el-table-column align="center" label="采购总金额"   property="totalPurchasePrice"  ></el-table-column>
          <el-table-column align="center" label="实收总金额"   property="totalRealityHarvestPrice"  ></el-table-column>
          <el-table-column align="center" label="审核人"   property="auditUserName"  ></el-table-column>
          <el-table-column align="center" label="审核时间"   property="auditTime"  width="180"></el-table-column>
          <el-table-column align="center" label="状态"   property="accountsCondition"   >
            <template slot-scope="scope">

              <span v-show="scope.row.accountsCondition=='2'">待审核</span>
              <span v-show="scope.row.accountsCondition=='3'">审核通过</span>

            </template>
          </el-table-column>
          <el-table-column align="center" label="备注"   property="remark"  show-overflow-tooltip ></el-table-column>
          <el-table-column align="center" label="管理" width="200"  fixed="right">
            <template slot-scope="scope">
              <el-button size="mini" type="primary"   @click="edit( scope.row)">查看</el-button>
              <el-button v-if="auditQX==1" v-show="scope.row.accountsCondition=='2' ||scope.row.accountsCondition=='4'" size="mini" type="warning"   @click="shBtn( scope.row)">审核</el-button>
              <el-button v-if="auditQX==1" v-show="scope.row.accountsCondition=='3'" size="mini" type="warning"   @click="fsBtn( scope.row)">反审</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          style="margin-top: 20px;text-align: right"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 30, 40]"
          :current-page="queryParams.current"
          :page-size="queryParams.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>

    </div>
    <add-Dialog v-if="newShow" :addData="addData" @callback="callback"></add-Dialog>
  </div>
</template>

<script>
import request from '@/utils/request'
import {getnewDat,getCurrWeek,getCurrentMonthFirst} from "@/utils/index"
import addDialog from './addDialog'
export default {
  components:{
    addDialog

  },
  data() {
    return {
      deleteQX:localStorage.getItem("delete"),//删除权限
      addQX:localStorage.getItem("add"),//保存权限
      auditQX:localStorage.getItem("audit"),//审核权限
      newShow:false,
      addData:{},
      total:0,
      loading:false,
      radio:'1',
      queryParams:{
        current:1,
        size:10,
        selectType:'0',
        accountsPayableCode:'',//采购单号
        supplierId:'',//供应商id
        procurementStatus:'',//状态

      },
      //供应商
      gysList:[],
      //状态   1未提交 2待审核 3完成审核 4驳回
      ztList:[

        {value:'2',label:'待审核'},
        {value:'3',label:'审核通过'},

      ],
      //单据日期
      djDateList:[],
      //付款日期
      fkDateList:[],
      //列表数据
      dataList:[],

    }
  },
  created() {
    this.getGYSList();
    this.getList();
  },
  methods: {
    //计划列表
    jihuaChange:function (row){
      if(row==0){
        this.djDateList=[]
        this.queryParams.crtTimeStart =''
        this.queryParams.crtTimeEnd = ''
        this.getList()
      }else if(row==1){
        this.djDateList=getnewDat()
        this.queryParams.crtTimeStart = this.djDateList[0]
        this.queryParams.crtTimeEnd = this.djDateList[1]
        this.getList()
      }else if(row==2){
        this.djDateList=getCurrWeek()
        this.queryParams.crtTimeStart = this.djDateList[0]
        this.queryParams.crtTimeEnd = this.djDateList[1]
        this.getList()
      }else if(row==3){
        this.djDateList=getCurrentMonthFirst()
        this.queryParams.crtTimeStart = this.djDateList[0]
        this.queryParams.crtTimeEnd = this.djDateList[1]
        this.getList()
      }
      console.log('计划监听时间',this.djDateList)
    },

    //新增
    newAdd:function (){
      var obj={}
      obj.leixing='post'
      this.addData = obj
      this.newShow = true

    },
    //修改
    edit:function (row){
      var obj={}
      obj.leixing='put'
      obj.id=row.accountsPayableId
      obj.purchasePlanStatus=row.accountsCondition
      this.addData = obj
      this.newShow = true
    },
    //单据日期修改
    riqiChange:function (row){
      console.log('监听日期',row)
      if(row){
        this.queryParams.crtTimeStart = row[0]
        this.queryParams.crtTimeEnd = row[1]
      }else {
        this.queryParams.crtTimeStart = ''
        this.queryParams.crtTimeEnd = ''
      }
    },
    fkriqichange:function (da){
      this.queryParams.payTime1=da[0];
      this.queryParams.payTime1=da[1];
    },
    //分页查询
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.queryParams.current = val
      this.getList()
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.queryParams.size = val
      this.getList()
    },
    //弹框返回事件
    callback:function (item){
      this.newShow = false
      this.getList()
    },
    //搜索
    getList:function (){
      this.loading=true
      request({
        url: '/wh/accountsPayable/page',
        method: 'get',
        params:this.queryParams
      }).then(response => {
        this.loading=false
        if(response.code=='200'){
          this.dataList = response.data.records
          this.total =response.data.total
        }else {
          this.dataList=[]
          this.$message({
            type: 'warning',
            message:response.msg
          });
        }
      });
    },
    //查询供应商
    getGYSList:function (){
      request({
        url: '/wh/supplier/list',
        method: 'GET',
      }).then(response => {
        this.gysList = response.data
      });
    },
    //删除
    handleDelete:function (row){
      this.$confirm('此操作将永久删除该单号, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.shanchu(row)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //删除接口
    shanchu:function (row){
      request({
        url: '/wh/procurement/del?ids='+row.procurementId,
        method: 'post',
      }).then(response => {
        this.$message({
          type: 'success',
          message:response.msg
        });
        this.getList()
      });
    },
    //审核
    shBtn:function (row){
      this.$confirm('此操作将审核通过, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.ShBtn(row);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消审核'
        });
      });
    },
    //审核
    ShBtn:function (row){
      request({
        url: '/wh/accountsPayable/audit?id='+row.accountsPayableId,
        method: 'put',
      }).then(response => {
        if(response.code==200){
          this.$message({
            type: 'success',
            message:response.msg
          });
        }else {
          this.$message({
            type: 'warning',
            message:response.msg
          });
        }
        this.getList()
      });
    },
    //驳回
    fsBtn:function (row){
      this.$confirm('此操作将反审, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.bohui(row);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消反审'
        });
      });
    },
    //驳回
    bohui:function (row){
      request({
        url: '/wh/accountsPayable/rejected?id='+row.accountsPayableId,
        method: 'put',
      }).then(response => {
        if(response.code==200){
          this.$message({
            type: 'success',
            message:response.msg
          });
        }else {
          this.$message({
            type: 'warning',
            message:response.msg
          });
        }
        this.getList()
      });
    },

  }
}
</script>

<style  scoped >
.theDocumentary {

}
.theDocumentary .cgName {
  font-size: 20px;
}

</style>
